// pages/selectaddress/selectaddress.js
var app = new getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    allselectaddress:[]
  },
  myaddress:function(e){
    console.log(e)
    app.choice_address.id = e.currentTarget.dataset.id;
    app.choice_address.name = e.currentTarget.dataset.name;
    app.choice_address.phone = e.currentTarget.dataset.phone;
    app.choice_address.region = e.currentTarget.dataset.region;
    app.choice_address.address = e.currentTarget.dataset.address;
    wx.navigateBack();
  },
  edit: function () {
    
  },
  del: function (e) {
    console.log(e)
    var that = this;
    wx.request({
      url: app.globalData.api_url + "/OpenAPI/V1/address/deleteUserAddress",
      data: {
        token: app.user.token,
        addressId: e.currentTarget.dataset.id,
      },
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        that.onLoad();
      },
      fail: function (res) {
        console.log(res.data)
      }
    })
  },
  addaddress:function(){
    wx.navigateTo({
      url: '/pages/addaddress/addaddress'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.globalData.api_url + "/OpenAPI/v1/address/getUserAddress",
      data: {
        token: app.user.token,
        page: 1
      },
      method: 'GET',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        var list = res.data.data;
        that.setData({
          allselectaddress: list
        })
      },
      fail: function (res) {
        console.log(res.data)
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})